package module;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.w3c.dom.ls.LSException;

import bean.Item;
import bean.Mader;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import DateBase.Datebase;

public class IndexModule {
	Datebase con=new Datebase();
	
	public ArrayList getMaderMsg() throws SQLException{
		Connection conn=(Connection) con.getConnection();
		String sql="select * from mader limit 0,4";
		Statement st=(Statement) conn.createStatement();
		ResultSet rs =  st.executeQuery(sql);
		ArrayList list=new ArrayList();
		while(rs.next()){
			Mader mader=new Mader();
			mader.setName(rs.getString("madename"));
			mader.setImgsrc(rs.getString("imgsrc"));
			mader.setDes(rs.getString("madedes"));
			list.add(mader);
		}
		return list;
		
	}
	public ArrayList getItem1() throws SQLException{
		Connection conn=(Connection) con.getConnection();
		String sql="select * from shop limit 0,4";
		Statement st=(Statement) conn.createStatement();
		ResultSet rs=st.executeQuery(sql);
		ArrayList list=new ArrayList();
		while(rs.next()){
			Item item=new Item();
			item.setId(rs.getInt("shopid"));
			item.setName(rs.getString("shopname"));
			item.setPrice(rs.getFloat("price"));
			item.setNum(rs.getInt("num"));
			item.setPicture(rs.getString("picture"));
			item.setInformation(rs.getString("shopinformation"));
			list.add(item);
		}
		return list;
	}
	public ArrayList getItem2() throws SQLException{
		Connection conn=(Connection) con.getConnection();
		String sql="select * from shop limit 4,4";
		Statement st=(Statement) conn.createStatement();
		ResultSet rs=st.executeQuery(sql);
		ArrayList list=new ArrayList();
		while(rs.next()){
			Item item=new Item();
			item.setId(rs.getInt("shopid"));
			item.setName(rs.getString("shopname"));
			item.setPrice(rs.getFloat("price"));
			item.setNum(rs.getInt("num"));
			item.setPicture(rs.getString("picture"));
			item.setInformation(rs.getString("shopinformation"));
			list.add(item);
		}
		return list;
	}
}
